package com.etlmaster.executor.steps.datax;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Map;

import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.utils.DpExecutorUtils;
import com.etlmaster.executor.utils.StepState;

import freemarker.core.FreeMarkerTemplate;

/**
 * 
 * @author Wugf
 * @date 2016-03-08
 */
public class DataxReader {

	public static int runDataxReader(int hashCode,String pluginName,Map<String,String> data,StepMeta meta){
		int flag=StepState.RUNNING_SUCCESSED;
		String reader=FreeMarkerTemplate.getFpl(pluginName, data);
		if(reader==null){
			meta.log("ERROR","生成读取hivereadplugin error!");
			return StepState.RUNNING_FAILED;
		}else{
			meta.log("INFO","生成reader配置成功");
		}
		try {
			File f = null;
			
			String logPath = DpExecutorUtils.getLogPath()+"/";
			meta.log("DEBUG",logPath);
			f = DpExecutorUtils.writeToFile(reader.toString(), "xml", logPath,hashCode);
			String fileName=f.getPath();
			meta.getStepState().getReturnValue().put("readerjobconf",fileName);
		} catch (IOException e) {
			flag = StepState.RUNNING_FAILED;
			meta.log("ERROR",e.getMessage());
			meta.log("ERROR","生成配置文件错误");
		}
		
		return flag;
	}
}
